namespace SimpleWebServices.Configuration
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using Xunit;

    public sealed class RedirectionSettingFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RedirectionSetting>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .XmlRoot("redirect")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            RedirectionSetting actual = "<redirect from='/foo' to='/bar' />".Deserialize<RedirectionSetting>();

            Assert.NotNull(actual);

            Assert.Equal<string>("/foo", actual.From);
            Assert.Equal<string>("/bar", actual.To);
        }

        [Fact]
        public void deserializeEmpty()
        {
            RedirectionSetting actual = "<redirect />".Deserialize<RedirectionSetting>();

            Assert.NotNull(actual);

            Assert.Null(actual.From);
            Assert.Null(actual.To);
        }

        [Fact]
        public void serialize()
        {
            RedirectionSetting obj = new RedirectionSetting
            {
                From = "/foo",
                To = "/bar"
            };

            XPathNavigator navigator = obj.Serialize().CreateNavigator();

            Assert.True((bool)navigator.Evaluate("1=count(/redirect[@from='/foo'][@to='/bar'])"));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RedirectionSetting());
        }

        [Fact]
        public void prop_From()
        {
            Assert.True(new PropertyExpectations(typeof(RedirectionSetting).GetProperty("From"))
                .XmlAttribute("from")
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_To()
        {
            Assert.True(new PropertyExpectations(typeof(RedirectionSetting).GetProperty("To"))
                .XmlAttribute("to")
                .IsAutoProperty<string>()
                .Result);
        }
    }
}